home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <fcntl.h>
- #include <io.h>
- main()
- {
- char fname[40], *p_fname;
- int filehandle;
- printf("Enter name of file to open using _open: ");
- p_fname = gets(fname);
-
- /* Open the file using _open */
- if((filehandle = _open(p_fname, O_RDONLY)) == -1)
- {
- printf("Error opening file:%s\n", fname);
- exit(0);
- }
- printf("File %s opened. \n", fname);
-
- /* Now close file */
- if( _close(filehandle) != 0)
- {
- perror("Error closing file with _close");
- exit(0);
- }
- printf("File %s closed.\n", fname);
- }